package com.guodefu.demo.controller;

import com.guodefu.demo.domain.Payment;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/testMongoDB")
public class TestMongoDBController {
    private MongoTemplate mongoTemplate;

    public TestMongoDBController(MongoTemplate mongoTemplate) {
        this.mongoTemplate = mongoTemplate;
    }

    @PostMapping("/save")
    public List<Payment> testMongoDB(@RequestBody Payment payment) {
        mongoTemplate.save(payment);
        return mongoTemplate.findAll(Payment.class);
    }

}
